<!DOCTYPE html>
<html lang="en">

<head>
    <title>Example</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        table {
            border: solid thin black;
            border-collapse: collapse;
            margin: 10px;
            float: left;
        }
        
        td {
            padding: 4px 5px;
        }
        
        p {
            clear: left;
        }
    </style>
</head>

<body>
    <table border="1">
        <thead>
            <tr>
                <th>Fruit</th>
                <th>Color</th>
            </tr>
        </thead>
        <tbody id="fruitsBody">
            <tr id="targetrow">
                <td>Placeholder</tr>
            </tr>
        </tbody>
    </table>
    <p>
        <button id="ab">After Begin</button>
        <button id="ae">After End</button>
        <button id="bb">Before Begin</button>
        <button id="be">Before End</button>
    </p>

    <script>
        var target = document.getElementById('targetrow');
        var buttons = document.getElementsByTagName('button');
        for (let i = 0; i < buttons.length; i++) {
            buttons[i].onclick = handleButtonPress;
        }

        function handleButtonPress(e) {
            if (e.target.id == "ab") {
                target.insertAdjacentHTML('afterbegin', "<td>After Begin</td>");
            } else if (e.target.id == "be") {
                target.insertAdjacentHTML("beforeend", "<td>Before End</td>");
            } else if (e.target.id == "bb") {
                target.insertAdjacentHTML("beforebegin", "<tr><td colspan='2'>Before Begin</td></tr>");
            } else {
                target.insertAdjacentHTML("afterend", "<tr><td colspan='2'>After Begin</td></tr>");
            }
        }
    </script>
</body>

</html>